{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16 node log records so far\n",
      "7 usage records so far\n",
      "{'customer_id': 'cust-0d24f9f3-e6cd-43dd-a3e4-b0f66997e1a0',\n",
      " 'dimension': None,\n",
      " 'metering_rec_id': None,\n",
      " 'quantity': 1,\n",
      " 'status': 1,\n",
      " 'timestamp': numpy.datetime64('2019-05-15T13:58:00.000000000')}\n",
      "{'customer_id': 'cust-0d24f9f3-e6cd-43dd-a3e4-b0f66997e1a0',\n",
      " 'dimension': 'routers',\n",
      " 'metering_rec_id': None,\n",
      " 'quantity': 12,\n",
      " 'status': 1,\n",
      " 'timestamp': numpy.datetime64('2019-05-15T13:58:00.000000000')}\n",
      "{'customer_id': 'cust-0d24f9f3-e6cd-43dd-a3e4-b0f66997e1a0',\n",
      " 'dimension': None,\n",
      " 'metering_rec_id': None,\n",
      " 'quantity': 0,\n",
      " 'status': 1,\n",
      " 'timestamp': numpy.datetime64('2019-05-15T13:56:00.000000000')}\n",
      "{'customer_id': 'cust-0d24f9f3-e6cd-43dd-a3e4-b0f66997e1a0',\n",
      " 'dimension': None,\n",
      " 'metering_rec_id': None,\n",
      " 'quantity': 1,\n",
      " 'status': 1,\n",
      " 'timestamp': numpy.datetime64('2019-05-15T13:59:00.000000000')}\n",
      "{'customer_id': 'cust-0d24f9f3-e6cd-43dd-a3e4-b0f66997e1a0',\n",
      " 'dimension': 'routers',\n",
      " 'metering_rec_id': None,\n",
      " 'quantity': 12,\n",
      " 'status': 1,\n",
      " 'timestamp': numpy.datetime64('2019-05-15T13:59:00.000000000')}\n",
      "{'customer_id': 'cust-0d24f9f3-e6cd-43dd-a3e4-b0f66997e1a0',\n",
      " 'dimension': None,\n",
      " 'metering_rec_id': None,\n",
      " 'quantity': 1,\n",
      " 'status': 1,\n",
      " 'timestamp': numpy.datetime64('2019-05-15T13:57:00.000000000')}\n",
      "{'customer_id': 'cust-0d24f9f3-e6cd-43dd-a3e4-b0f66997e1a0',\n",
      " 'dimension': 'routers',\n",
      " 'metering_rec_id': None,\n",
      " 'quantity': 4,\n",
      " 'status': 1,\n",
      " 'timestamp': numpy.datetime64('2019-05-15T13:57:00.000000000')}\n"
     ]
    }
   ],
   "source": [
    "DBFILE = '.crossbar/.db-mrealm-953be332-d1e6-4b58-8416-8b994bc01077/'\n",
    "GDBFILE = '.crossbar/.db-controller'\n",
    "\n",
    "from pprint import pprint\n",
    "import zlmdb\n",
    "from crossbarfx.master.database.mrealmschema import MrealmSchema\n",
    "from crossbarfx.master.database.globalschema import GlobalSchema\n",
    "\n",
    "db = zlmdb.Database(DBFILE, maxsize=2**30, readonly=False)\n",
    "schema = MrealmSchema.attach(db)\n",
    "\n",
    "gdb = zlmdb.Database(GDBFILE, maxsize=2**30, readonly=False)\n",
    "gschema = GlobalSchema.attach(gdb)\n",
    "\n",
    "with db.begin() as txn:\n",
    "    with gdb.begin() as gtxn:\n",
    "        cnt = schema.mnode_logs.count(txn)\n",
    "        print('{} node log records so far'.format(cnt))\n",
    "\n",
    "        cnt = gschema.usage.count(gtxn)\n",
    "        print('{} usage records so far'.format(cnt))\n",
    "        for key, rec in gschema.usage.select(gtxn, return_keys=True):\n",
    "            pprint(rec.marshal())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
